$(document).ready(function(){
	
	var pos = {
		"0": {"left": 0, "top": 2},
		"1": {"left": 235, "top": 1},
		"2": {"left": 470, "top": 0},
		"3": {"left": 705, "top": 1}
	};
	
	function get_min_top()
	{
		var val = pos['0']['top'];
		var ref = "0";
		
		$.each(pos, function(key, value){
			if (value['top'] < val)
			{
				val = value['top'];
				ref = key;
			}
			
		});
		
		return ref;
		
	}
	
	function get_min_left()
	{
		var val = pos['0']['left'];
		var ref = "0";
		
		$.each(pos, function(key, value){
			if (value['left'] < val)
			{
				val = value['left'];
				ref = key;
			}
		});
		
		return ref;
		
	}
	
	$('.tala').each(function(index){
		var height =  $(this).attr('data-height') + 'px';
		$(this).css('height', height);
		
		var ref = get_min_top();

		$(this).css({
			'top': pos[ref]['top'] + 'px',
			'left': pos[ref]['left'] + 'px'
		});
		
		pos[ref]['top'] += (25 + Number($(this).attr('data-height')));
		
	});
	
	
	
});